import { Controller, Get, Post, Param, Body, UsePipes, ValidationPipe, UseInterceptors, Query, Put, Delete } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiQuery } from '@nestjs/swagger';
import { TransformInterceptor } from 'src/interceptor/transform.interceptor';

import { CreateDto } from './bucket.dto';
import { MinioClient } from '../app.minio';

@ApiTags('空间')
@Controller('bucket')
@UseInterceptors(TransformInterceptor)
export class BucketController {


    @Post('')
    @ApiOperation({ summary: '创建一个新空间' })
    async makeBucket( @Body() data: CreateDto) {
        return await new MinioClient().makeBucket(data);
    }
    @Get('')
    @ApiOperation({ summary: '列出所有空间' })
    async listBuckets() {
        return await new MinioClient().listBuckets();
    }

    @Get(':name')
    @ApiOperation({ summary: '验证存储空间是否存在' })
    async bucketExists( @Param('name') name: string) {
        return await new MinioClient().bucketExists(name);
    }
    @Delete(':name')
    @ApiOperation({ summary: '删除存储空间' })
    async removeBucket( @Param('name') name: string) {
        return await new MinioClient().removeBucket(name);
    }
    @Get(':name/objects')
    @ApiOperation({ summary: '列出存储空间中所有对象' })
    async listObjects( @Param('name') name: string) {
        return await new MinioClient().listObjects(name)
    }

    @Get(':name/listIncompleteUploads')
    @ApiOperation({ summary: '列出存储空间中未完整上传的对象' })
    async listIncompleteUploads( @Param('name') name: string) {
        return await new MinioClient().listIncompleteUploads(name)
    }
}
